//
//  UIBarButtonItem+Extension.swift
//  Weibo
//
//  Created by 张远文 on 16/5/10.
//  Copyright © 2016年 张远文. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    //自定义便利构造函数
    convenience init(imageName: String, target: AnyObject?, actionName: String?) {
        
        let btn = UIButton(type: UIButtonType.Custom)
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        if let action = actionName, targetObj = target {
            btn.addTarget(targetObj, action: Selector(action), forControlEvents: .TouchUpInside)
        }
        btn.sizeToFit()
        self.init(customView: btn)
    }
}
